<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .imgBox {
      margin: 1000px auto;
      width: 800px;
      overflow: hidden;
      background-color: #888;
    }

    .imgBox img {
      width: 100%;
      vertical-align: middle;
    }
  </style>
</head>

<body>
  <div class="imgBox">
    <img src="" data-img="https://www.itcast.cn/images/newslide/homepageandphone/20224109184146299.jpg" alt="">
  </div>
  <script>
    const oImg = document.querySelector('img');

    const observer = new IntersectionObserver(([{ isIntersecting }]) => {
      if (isIntersecting) {
        oImg.src = oImg.dataset.img
        observer.unobserve(oImg)
      }
    })
    observer.observe(oImg)
  </script>
</body>

</html>